import useAntdList from "@/hooks/useAntdList"
import useAntdModal, { AntdModalProps } from "@/hooks/useAntdModal"
import { queryCodeupAppLink } from "@/service/deliver"
import { formatDate } from "@/utils/utils"
import { Button, Drawer, Space, Table } from "antd"
import { useEffect } from "react"
import AddSubApp from "./AddSubApp"
const ReleasePlan = ({ env }: any) => {

    return
}
const SubAppDrawer = ({ modalProps, payload }: AntdModalProps) => {
    const { tableProps, run } = useAntdList(() => queryCodeupAppLink({ id: payload.id }), {manual:true})
    const addSubApp = useAntdModal();
    const onDeploy = (_) => {
        // console.log({env,..._})
    }
    useEffect(() => {
        
        if (modalProps.open) {
            //   @ts-ignore
            run()
        }

    }, [modalProps.open])
    return <Drawer
        width={600}
        extra={
            <Space>

                <Button type="primary" onClick={() => addSubApp.openModal({
                    parentId: payload.id
                })}>
                    增加子应用
                </Button>
            </Space>
        }
        {...modalProps}>
        <AddSubApp {...addSubApp} />
        <Table rowKey='id' {...tableProps} size='small' columns={[{
            dataIndex: 'name',
            title: '应用名称'
        }, {
            title: '版本',
            dataIndex: 'gitUrl',
          
        }, {
            dataIndex: 'createdAt',
            title: '创建时间',
            render: (_) => formatDate(_)

        }, {
            title: '操作',
            render(_) {
                return <Space>
                    <Button onClick={() => onDeploy(_)} type='link'>部署</Button>
                    <Button danger  type='link'>删除</Button>
                </Space>
            }
        }]} />
    </Drawer>
}
export default SubAppDrawer